home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-10-18 | 5.9 KB | 307 lines | [TEXT/MMCC] |
- /*
- File: App.cp
-
- Contains: Boilerplate application-specific code.
-
- Written by: Dave Falkenburg
-
- Copyright: © 1993-94 by Dave Falkenburg, all rights reserved.
-
- Change History (most recent first):
-
- */
-
- #include <Windows.h>
- #include <Dialogs.h>
- #include <Menus.h>
- #include <Desk.h>
- #include <Errors.h>
- #include <Resources.h>
- #include <StandardFile.h>
- #include <Devices.h> // was <Desk.h>
-
- #include "AppLib.h"
- #include "Window.h"
- #include "StandardMenus.h"
- #include "SplashWindow.h"
-
- #include "GXToolWindow.h"
- #include "GXDocWindow.h"
- #include "PreferencesDialogWindow.h"
- #include "MailableDocWindow.h"
-
- #include "Preferences.h"
-
- AppPreferences gPreferences;
-
- // Function Prototypes:
-
- void AboutBox(void);
- void OpenExistingDocument(void);
-
-
- #define kAboutBoxFor68K 256
- #define kAboutBoxForPowerPC 257
- #define iCreditsButton 2
-
- #define kCreditsBox 258
-
-
- #if qUseQuickDrawGX
- // gAppPrintingOverrideUPP is a universal proc pointer for our printing event
- // override. This is so that our override can be native PowerPC code if necessary.
-
- GXPrintingEventUPP gAppPrintingOverrideUPP;
-
- // PrintingEventOverride is our generic event handler for QuickDrawGX.
- // It alows us to handle events while the QuickDrawGX movable modal
- // printing dialogs are displayed.
- static OSErr AppPrintingEventOverride(EventRecord *pEvent, Boolean theFilterEvent)
- {
- CSavePort aSavePort(nil);
-
- if (theFilterEvent == false)
- switch (pEvent->what)
- {
- case mouseDown:
- case keyDown:
- case autoKey:
- break;
-
- default:
- HandleEvent(pEvent);
- }
- return noErr;
- }
- #endif
-
-
- OSErr SetupApplication(void)
- {
- #if qUseQuickDrawGX
- if (gHasQuickDrawGX)
- gAppPrintingOverrideUPP = NewGXPrintingEventProc(AppPrintingEventOverride);
- #endif
-
- if (gHasAOCE)
- {
- MenuHandle hMenu = GetMenu(mDebug);
- if (hMenu)
- InsertMenu(hMenu, 0);
- EnableMenuItem(mDebug, iNewMailableWindow, true);
- }
-
- TGXToolWindow * someTools = new TGXToolWindow();
-
- gPreferences.fMailPreferences.fCreateMailerForNewDocuments = true;
-
- InitCursor();
- return (noErr);
- }
-
- void TearDownApplication(void)
- {
- DisposeRoutineDescriptor(gAppPrintingOverrideUPP);
- // Not much to do yet.
- }
-
- void HandleMenu(TWindow * topWindowObj, long menuCode)
- {
- short menu = (short) (menuCode >> 16);
- short item = (short) (menuCode & 0xffff);
- Str255 deskAccName;
-
- switch (menu)
- {
- case mApple:
- switch (item)
- {
- case iAbout:
- AboutBox();
- break;
-
- default:
- GetItem(GetMHandle(mApple),item,deskAccName);
- (void) OpenDeskAcc(deskAccName);
- break;
- }
- break;
-
- case mFile:
- switch (item)
- {
- case iNew:
- OpenNewDocument();
- break;
-
- case iOpen:
- OpenExistingDocument();
- break;
-
- case iClose:
- HandleClose(FrontNonFloatingWindow());
- break;
-
- case iPageSetup:
- case iCustomPageSetup:
- case iPrint:
- case iPrintOneCopy:
- WindowCommand(FrontNonFloatingWindow(), menu, item);
- break;
-
- case iPreferences:
- TPreferencesDialogWindow * prefsDialog = new TPreferencesDialogWindow;
- break;
-
- case iQuit:
- gDone = QuitApplication();
- break;
-
- default:
- WindowCommand(FrontNonFloatingWindow(), menu, item);
- break;
- }
- break;
-
- case mEdit:
- switch (item)
- {
- case iUndo :
- case iCut :
- case iCopy :
- case iPaste :
- case iSelectAll :
- if (SystemEdit(item-1) == false)
- if (topWindowObj)
- topWindowObj->DoEditMenu(item);
- break;
- case iNextPage:
- case iPreviousPage:
- case iGotoPage:
- WindowCommand(FrontNonFloatingWindow(), menu, item);
- break;
- case iShowOrHideClipboard:
- break;
- }
-
- case mDebug:
- switch(item)
- {
- case iNewMailableWindow:
- TMailableDocWindow *aWackyThing = new TMailableDocWindow;
- break;
-
- default:
- break;
- }
- break;
-
- default:
- break;
- }
- HiliteMenu(0);
- }
-
- void AboutBox(void)
- {
- Handle versionHandle;
- StringPtr nullStr = (StringPtr) "\p";
- StringPtr shortVersionString = nullStr;
- short itemHit;
-
- versionHandle = GetResource('vers',1);
- if (versionHandle)
- shortVersionString = (StringPtr) ((char *) *versionHandle + 6);
- ParamText(shortVersionString,nullStr,nullStr,nullStr);
- ReleaseResource(versionHandle);
-
- #ifndef powerc
- itemHit = StandardAlert(kAboutBoxFor68K);
- #else
- itemHit = StandardAlert(kAboutBoxForPowerPC);
- #endif
-
- if (itemHit == iCreditsButton)
- StandardAlert(kCreditsBox);
- }
-
-
- void OpenExistingDocument(void)
- {
- StandardFileReply aSfReply;
- SFTypeList ourTypes;
- Point where = { -1, -1 };
-
- ourTypes[0] = 'sjob';
-
- HiliteWindowsForModalDialog(false);
- CustomGetFile((FileFilterYDUPP) nil, 1, ourTypes, &aSfReply, 0, where,
- (DlgHookYDUPP) nil,StandardDialogFilterYD, nil,nil,nil);
- HiliteWindowsForModalDialog(true);
- if (aSfReply.sfGood)
- {
- LetterDescriptor aLetterDescriptor;
-
- aLetterDescriptor.onDisk = true;
- aLetterDescriptor.u.fileSpec = aSfReply.sfFile;
- (void)OpenDocument(&aLetterDescriptor, nil);
- }
- }
-
- void ConvertClipboard(void)
- {
- }
-
- OSErr OpenNewDocument(void)
- {
- TGXDocWindow *pNewWindow = new TGXDocWindow();
- if (pNewWindow)
- {
- pNewWindow->CreateSampleImage();
- return noErr;
- }
- return memFullErr;
- }
-
- /****
- struct LetterDescriptor {
- Boolean onDisk;
- union {
- FSSpec fileSpec;
- LetterSpec mailboxSpec;
- } u;
- struct LetterSpec {
- unsigned long spec[3];
- };
- };
- ****/
- OSErr OpenDocument(LetterDescriptor* pDocument, void * /*unused*/)
- {
- TGXDocWindow *pNewWindow = new TGXDocWindow();
- if (pNewWindow)
- {
- pNewWindow->SetDocFile(&pDocument->u.fileSpec);
- pNewWindow->ReadPage(1);
- return noErr;
- }
- return memFullErr;
- }
-
- OSErr PrintDocument(LetterDescriptor * /* theDocument */, void * /*unused*/)
- {
- return noErr;
- }
-
- Boolean QuitApplication(void)
- {
- WindowPtr pFrontNonFloater;
-
- while ((pFrontNonFloater = FrontNonFloatingWindow()), pFrontNonFloater)
- {
- HandleClose(pFrontNonFloater);
- if (pFrontNonFloater == FrontNonFloatingWindow()) // failed
- return false;
- }
- return true;
- }
-